<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_content
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;
$db = & JFactory::getDBO();
$Itemid = JRequest::getVar('Itemid','101');
$query = 'SELECT note FROM #__menu WHERE id='.$Itemid;					
$db->setQuery( $query );
$temmenu = $db->loadResult();
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
JHtml::_('behavior.caption');
?>

<?php
//Adding the location on the title bar
$page_title = $this->category->title;
if ($this->params->get('show_category_title')){
	JFactory::getDocument()->setTitle($page_title.JText::_('WMC_OUTLET_PAGE_TITLE'));
}else{
	JFactory::getDocument()->setTitle($this->params->get('page_title').JText::_('WMC_OUTLET_PAGE_TITLE'));
}




jimport('joomla.language.helper');
$languages = JLanguageHelper::getLanguages('lang_code');
$lang_code = JFactory::getLanguage()->getTag();
$lang = $languages[$lang_code]->sef;


if($lang=="vn" || $lang=="vi-vn"){$linkform = "http://wmcvietnam.com/vn/tin-tuc-cua-nam";}
else{$linkform = "http://wmcvietnam.com/news-year";}

?>
<div class="blog<?php echo $this->pageclass_sfx;?>">
	<?php if ($this->params->get('show_page_heading', 1)) : ?>
	<div class="page-header">
		<h1 class="wmc_heading"><strong>
			<?php 
				$page_title = $this->category->title;
				if ($this->params->get('show_category_title')){
					echo $page_title;
				}else{
					echo $this->escape($this->params->get('page_heading')); 
				}
			 ?>
			 <?php if ($this->category->id == 17): ?>			 	
				<a class="tracking_restaurant_reservation_ga" href="<?php echo JRoute::_('index.php?option=com_wmcreservation&view=wmcreservation&Itemid=168')?>">
                <div class="reservation <?php echo "reservation_".$lang;?>"></div></a></strong></h1> 	
			 <?php endif ?>
	</div>
	<?php endif; ?>
	<?php if ($this->params->get('show_category_title', 1) or $this->params->get('page_subheading')) : ?>
	<h3> <?php echo $this->escape($this->params->get('page_subheading')); ?>
		<?php if ($this->params->get('show_category_title')) : ?>
		<!-- <span class="subheading-category"><?php echo $this->category->title;?></span> -->
		<?php endif; ?>

	</h3>
	<?php endif; ?>
	<?php if ($this->params->get('show_description', 1) || $this->params->def('show_description_image', 1)) : ?>
	<div class="category-desc">
		<?php if ($this->params->get('show_description_image') && $this->category->getParams()->get('image')) : ?>
			<img src="<?php echo $this->category->getParams()->get('image'); ?>"/>
		<?php endif; ?>
		<?php if ($this->params->get('show_description') && $this->category->description) : ?>
			<?php echo JHtml::_('content.prepare', $this->category->description, '', 'com_content.category'); ?>
		<?php endif; ?>
		<div class="clr"></div>
	</div>
	<?php endif; ?>
	<?php $leadingcount = 0; ?>
	<?php if (!empty($this->lead_items)) : ?>
	<div class="items-leading contentmain">
    	
        <?php
        if($temmenu=="gallery"){
			?>
			<div class="categallery">
                <div id="portfolio" class="portfolio-normal clearfix">
                    <?php foreach ($this->lead_items as &$item) : 
						
						$params = &$item->params;
						$images = json_decode($item->images);

						//Mouse hover on porfolio
		                $desc = '';
		                $add = '';
		                $tel = '';
		                $fax = '';
		                $web = '';
		                $open_hour = '';
		                $email = '';
		                $social = '';       

		                $info = $item->introtext;
		                $info_array = explode('<li>', $info);

		                $desc = $info_array[0];
		               for ($J=1; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[1],JText::_('WMC_OUTLET_ADDRESS'))) {
		                       $add = substr($info_array[1], strlen(JText::_('WMC_OUTLET_ADDRESS'))+6);
		                       break;
		                   }
		               }
		               for ($J=2; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_TEL'))) {
		                       $tel = str_replace('<br />',JText::_('WMC_OUTLET_OR'),$info_array[$J]);
		                       $tel = substr($tel,strlen(JText::_('WMC_OUTLET_TEL'))+6);
		                       $tel = strip_tags($tel);
		                       break;
		                   }
		               }
		               for ($J=1; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_FAX'))) {
		                       $fax = $info_array[$J];
		                   }
		               }
		               for ($J=1; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_WEBSITE'))) {
		                       $web = strip_tags($info_array[$J]);
		                       $web = explode('WEBSITE', $web);
		                       $web = $web[1];
		                   }
		               }
		               for ($J=1; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_OPENING_HOURS'))) {                       
		                       $open_hour = substr($info_array[$J],strlen(JText::_('WMC_OUTLET_OPENING_HOURS'))+6);
		                       $open_hour = strip_tags($open_hour);
		                       break;
		                   }
		               }
		               for ($J=1; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_EMAIL'))) {
		                       $email = $info_array[$J];
		                   }
		               }
		               for ($J=1; $J < count($info_array) ; $J++) { 
		                   if (stripos($info_array[$J],JText::_('WMC_OUTLET_SOCIAL'))) {
		                       $social = $info_array[$J];
		                   }
		               }
						
					?>
                        <div class="portfolio-item">
                            <div class="portfolio-image">
                                <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)); ?>">
                                	<img alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>" src="<?php echo htmlspecialchars($images->image_intro); ?>" />
                                	<div class="item-overlay overlay-icon-pic"><span></span></div>
                                </a>
                            </div>
                            <div class="portfolio-desc">
                                <h2>
                                    <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)); ?>"> 
										<?php echo $this->escape($item->title); ?>
                                    </a>	
                                </h2>
                            </div>
                            <div class="hover-detail-item">
			                    <?php 
			                        $image = json_decode($item->images);
			                        $logo_outlet = htmlspecialchars($image->image_fulltext);
			                     ?>
			                    <div class="title-detail-item">
			                        <?php echo $item->title; ?>
			                    </div>
			                    <div class="content-detail-item">
			                        <div class="wraper-hover-item">
			                          <div class="image"><img alt="<?php echo $alt;?>" src="<?php echo $logo_outlet; ?>" /></div>
			                          <div class="descr"><?php echo $desc; ?></div>
			                        </div>
			                        
			                        <div style="clear:both;"></div>
			                        <!--  <?php echo strlen($desc) < 450 ? $desc : substr($desc,0,450).' ...' ?>   -->          
			                        <table class="info">
			                          <tr class="header">
			                            <td><strong><?php echo JText::_('WMC_OUTLET_ADDRESS').':';?></strong></td>
			                          </tr>
			                          <tr>
			                            <td><?php echo $add;?></td>
			                          </tr>
			                          <tr class="header">
			                            <td><strong><p><?php echo JText::_('WMC_OUTLET_TEL').': </strong>'.$tel;?></p></td>
			                          </tr>
			                          <?php if($open_hour){?> 
			                          <tr class="header">
			                            <td><strong><p><?php echo JText::_('WMC_OUTLET_OPENING_HOURS').': </strong>'.$open_hour;?></p></td>
			                          </tr>
			                          <?php } ?>
			                          <?php if($web){?> 
			                          <tr class="header">
			                            <td><strong><?php echo JText::_('WMC_OUTLET_WEBSITE') ; ?>:</strong><a target="_blank" href="//<?php echo $web;?>"><?php echo $web; ?></a></td>
			                          </tr>
			                          <?php } ?>
			                        </table>
			                    </div>
			                </div>
                        </div>
                    <?php endforeach; ?>
                </div>
			</div>
			<?php
		}
		else if($temmenu=="offers"){
			foreach ($this->lead_items as &$item) : ?>
            <div class="entry clearfix leading-<?php echo $leadingcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?> ">
                <?php
                    $this->item = &$item;
                    echo $this->loadTemplate('offers');
                ?>
            </div>
		<?php
			$leadingcount++;
			endforeach;
		}
		else if($temmenu=="careerjob"){
		?>
        <div class="careerjobpage">
            <h2 class="titleh4"><?php echo $this->params->get('page_heading');?></h2>
            <div class="careerjobitem">
                <table width="100%" border="1" cellpadding="0" cellspacing="0">
                <tr class="trtitle">
                    <td align="center" class="tdtitle"><?php echo JText::_('No.');?></td>
                    <td align="center" class="tdtitle"><?php echo JText::_('Vacancy title');?></td>
                    <td align="center" class="tdtitle"><?php echo JText::_('Property name');?></td>
                    <td align="center" class="tdtitle"><?php echo JText::_('Logo');?></td>
                </tr>
            <?php
			foreach ($this->lead_items as &$item) :
			?>
                <tr>
                    <td align="center"><?php echo $leadingcount+1; ?></td>
            <?php
					$this->item = &$item;
					echo $this->loadTemplate('careerjob');
			?>
                </tr>
            <?php
			$leadingcount++;
			endforeach;
		?>
                </table>
            </div>
            <?php
            $document = &JFactory::getDocument();
			$renderer   = $document->loadRenderer('modules');
			$position   = 'categoriesjob';
			$options   = array('style' => 'none');
			echo $renderer->render($position, $options, null);
			?>
        </div>
        <?php
		}
		else if($temmenu=="news"){
		?>
            <div class="leftcontent newswmc">
            <?php
                foreach ($this->lead_items as &$item) :
                    $this->item = &$item;
                    echo $this->loadTemplate('news');
                endforeach;
            ?>
            </div>
            <div class="rightcontent slidernews">
            	<script src="templates/protostar/js/jquery-ui.js"></script>
				<script>

                jQuery(function() {
                    var tabCounter = 2;
                    var tabs = jQuery( "#tabs" ).tabs();
                    tabs.bind( "keyup", function( event ) {
                        if ( event.altKey && event.keyCode === jQuery.ui.keyCode.BACKSPACE ) {
                            var panelId = tabs.find( ".ui-tabs-active" ).remove().attr( "aria-controls" );
                            jQuery( "#" + panelId ).remove();
                            tabs.tabs( "refresh" );
                        }
                    });
                });
				function formyearnews(yearnewsinput){
					var f=document.getElementById('yearnews');
					document.getElementById('yearnewsofinput').value = yearnewsinput;
					f.submit();
				}
                </script>
                <div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs">
                    <ul role="tablist" class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                        <li aria-selected="true" aria-controls="tabs-1" class="ui-state-default ui-corner-top">
                            <a id="ui-id-1" class="ui-tabs-anchor" href="#tabs-1">
                                <?php echo JText::_('Recent Posts'); ?>
                            </a>
                        </li>
                        <!--<li aria-selected="true" aria-controls="tabs-2" class="ui-state-default ui-corner-top">
                            <a id="ui-id-2" class="ui-tabs-anchor" href="#tabs-2">
                                <?php echo JText::_('Categories'); ?>
                            </a>
                        </li>-->
                        <li aria-selected="true" aria-controls="tabs-3" class="ui-state-default ui-corner-top">
                            <a id="ui-id-3" class="ui-tabs-anchor" href="#tabs-3">
                                <?php echo JText::_('Year'); ?>
                            </a>
                        </li>
                    </ul>
                    <div class="ui-tabs-panel" id="tabs-1">
                    	<?php
						$sqlitem="SELECT * from #__content where catid='14' and state=1 order by publish_up desc";
						$db->setQuery($sqlitem);
						$rowitems = $db->loadObjectList();
						for($i=0;$i<count($rowitems);$i++){
							$itemdate = $rowitems[$i]->publish_up;
							$linkrecent='index.php?option=com_content&view=article&id='.$rowitems[$i]->id.':'.$rowitems[$i]->alias.'&catid='.$rowitems[$i]->catid.'&Itemid=109';
						?>
							<a href="<?php echo $linkrecent;?>">
								<?php echo $rowitems[$i]->title;?><br /><span class="datepublish"><?php echo date('jS M, Y', strtotime($itemdate)); ?></span>
							</a>
						<?php
						}
						?>
                    </div>
                    <!--<div style="display: block;" class="ui-tabs-panel" id="tabs-2">
                    <?php
                    foreach ($this->lead_items as &$item) :
						$itemdate = $item->publish_up;
                    ?>
                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid)); ?>">
                            <?php echo $this->escape($item->title); ?><br /><span class="datepublish"><?php echo date('jS M, Y', strtotime($itemdate)); ?></span>
                        </a>
                    <?php
                    endforeach;
                    ?>
                    </div>-->
                    <div class="ui-tabs-panel" id="tabs-3">
                    <form action="<?php echo $linkform;?>" method="post" id="yearnews" class="yearnews" name="yearnews" >
						<?php
                        $datenow = date('Y-d-m');
                        $datenow = explode('-',$datenow);
                        $datenow = $datenow[0];
                        for($i=$datenow;$i>=2011;$i--){
						?>
							<button id="yearnewsof" name="yearnewsof" class="yearnewsof" value="<?php echo $i;?>" onclick="formyearnews(<?php echo $i;?>);">
							<?php echo $i;?>
                            </button>
                        <?php
                        }
                        ?>
                        <input type="hidden" name="yearnewsofinput" id="yearnewsofinput" value="" />
                    </form>
                    </div>
                </div>
                
           	</div>
        
        <?php
		}
		else{
			foreach ($this->lead_items as &$item) : ?>
            <div class="entry clearfix leading-<?php echo $leadingcount; ?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?> ">
                <?php
                    $this->item = &$item;
                    echo $this->loadTemplate('item');
                ?>
            </div>
            <div class="clearfix"></div>
            <div class="article_separator"></div>
		<?php
			$leadingcount++;
		?>
		<?php 
			endforeach; 
		}
		?>
	</div><!-- end items-leading -->
	<div class="clearfix"></div>
	<?php endif; ?>
	<?php
	$introcount = (count($this->intro_items));
	$counter = 0;
?>
	<?php if (!empty($this->intro_items)) : ?>
	<?php foreach ($this->intro_items as $key => &$item) : ?>
	<?php
		$key = ($key - $leadingcount) + 1;
		$rowcount = (((int) $key - 1) % (int) $this->columns) + 1;
		$row = $counter / $this->columns;

		if ($rowcount == 1) : ?>
		<div class="items-row cols-<?php echo (int) $this->columns;?> <?php echo 'row-'.$row; ?> row-fluid">
		<?php endif; ?>
			<div class="span<?php echo round((12 / $this->columns));?>">
				<div class="item column-<?php echo $rowcount;?><?php echo $item->state == 0 ? ' system-unpublished' : null; ?>">
					<?php
					$this->item = &$item;
					echo $this->loadTemplate('item');
				?>
				</div><!-- end item -->
				<?php $counter++; ?>
			</div><!-- end spann -->
			<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>			
		</div><!-- end row -->
			<?php endif; ?>
	<?php endforeach; ?>
	<?php endif; ?>
	
	<?php if (!empty($this->link_items)) : ?>
	<div class="items-more">
    	<h3><?php echo JTEXT::_('More Article'); ?> ...</h3>
		<?php echo $this->loadTemplate('links'); ?>
	</div>
	<?php endif; ?>
	<?php if (!empty($this->children[$this->category->id])&& $this->maxLevel != 0) : ?>
	<div class="cat-children">
		<h3> <?php echo JTEXT::_('JGLOBAL_SUBCATEGORIES'); ?> </h3>
		<?php echo $this->loadTemplate('children'); ?> </div>
	<?php endif; ?>
	<?php if (($this->params->def('show_pagination', 1) == 1  || ($this->params->get('show_pagination') == 2)) && ($this->pagination->get('pages.total') > 1)) : ?>
	<div class="pagination">
		<?php  if ($this->params->def('show_pagination_results', 1)) : ?>
		<p class="counter pull-right"> <?php echo $this->pagination->getPagesCounter(); ?> </p>
		<?php endif; ?>
		<?php echo $this->pagination->getPagesLinks(); ?> </div>
	<?php  endif; ?>
</div>
